package com.clps.cn.Activite03;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;

import java.util.List;

public class HistoryQuery {


    public static void main(String[] args) {

        //01:得到ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();

        //02:得到historyService
        HistoryService historyService = defaultProcessEngine.getHistoryService();

        //03:得到HistoryActiviteInstanmceQuery对象
        HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();

        //设置流程的实例id
        historicActivityInstanceQuery.processInstanceId("2501");


        //04执行查询  ，排序startTime
        List<HistoricActivityInstance> list = historicActivityInstanceQuery.orderByHistoricActivityInstanceStartTime().asc().list();


        //05遍历查询结果
        for (HistoricActivityInstance instance : list) {
            System.out.println("instance.getActivityId() = " + instance.getActivityId());
            System.out.println("instance.getActivityName() = " + instance.getActivityName());
            System.out.println("instance.getProcessDefinitionId() = " + instance.getProcessDefinitionId());
            System.out.println("instance.getProcessInstanceId() = " + instance.getProcessInstanceId());
            System.out.println("==============================================================");
        }

    }
}
